import {createRouter, createWebHistory} from "vue-router";
import Home from "../views/Home.vue";

const routes = [
    {
        path: '/',
        redirect: '/login'
    }, {
        path: "/",
        name: "Home",
        component: Home,
        children: [
            {
                path: "/dashboard",
                name: "dashboard",
                meta: {
                    title: '系统首页'
                },
                component: () => import (
                /* webpackChunkName: "dashboard" */
                "../views/Dashboard.vue")
            }, {
                path: "/table",
                name: "basetable",
                meta: {
                    title: '表格'
                },
                component: () => import (
                /* webpackChunkName: "table" */
                "../views/BaseTable.vue")
            },{
                path: "/user",
                name: "user",
                meta: {
                    title: '用户'
                },
                component: () => import (
                    /* webpackChunkName: "table" */
                    "../views/power/User.vue")
            },
            {
                path: "/role",
                name: "role",
                meta: {
                    title: '角色'
                },
                component: () => import (
                    /* webpackChunkName: "table" */
                    "../views/power/Role.vue")
            },
            {
                path: "/permission",
                name: "permission",
                meta: {
                    title: '权限'
                },
                component: () => import (
                    /* webpackChunkName: "table" */
                    "../views/power/Permission.vue")
            },{
                path: "/charts",
                name: "basecharts",
                meta: {
                    title: '图表'
                },
                component: () => import (
                /* webpackChunkName: "charts" */
                "../views/BaseCharts.vue")
            }, {
                path: "/sysInfo",
                name: "sysInfo",
                meta: {
                    title: '系统监控'
                },
                component: () => import (
                    /* webpackChunkName: "charts" */
                    "../views/SysInfo.vue")
            }, {
                path: "/form",
                name: "baseform",
                meta: {
                    title: '表单'
                },
                component: () => import (
                /* webpackChunkName: "form" */
                "../views/BaseForm.vue")
            }, {
                path: "/pay",
                name: "pay",
                meta: {
                    title: '支付'
                },
                component: () => import (
                    /* webpackChunkName: "form" */
                    "../views/Pay.vue")
            }, {
                path: "/tabs",
                name: "tabs",
                meta: {
                    title: 'tab标签'
                },
                component: () => import (
                /* webpackChunkName: "tabs" */
                "../views/Tabs.vue")
            }, {
                path: "/donate",
                name: "donate",
                meta: {
                    title: '鼓励作者'
                },
                component: () => import (
                /* webpackChunkName: "donate" */
                "../views/Donate.vue")
            }, {
                path: "/fileManage",
                name: "fileManage",
                meta: {
                    title: '文件管理'
                },
                component: () => import (
                    /* webpackChunkName: "donate" */
                    "../views/file/File.vue")
            }, {
                path: "/permission",
                name: "permission",
                meta: {
                    title: '权限管理'
                    // permission: true
                },
                component: () => import (
                /* webpackChunkName: "permission" */
                "../views/power/Permission.vue")
            }, {
                path: "/i18n",
                name: "i18n",
                meta: {
                    title: '国际化语言'
                },
                component: () => import (
                /* webpackChunkName: "i18n" */
                "../views/I18n.vue")
            }, {
                path: "/upload",
                name: "upload",
                meta: {
                    title: '上传插件'
                },
                component: () => import (
                /* webpackChunkName: "upload" */
                "../views/Upload.vue")
            }, {
                path: "/icon",
                name: "icon",
                meta: {
                    title: '自定义图标'
                },
                component: () => import (
                /* webpackChunkName: "icon" */
                "../views/Icon.vue")
            }, {
                path: '/404',
                name: '404',
                meta: {
                    title: '找不到页面'
                },
                component: () => import (/* webpackChunkName: "404" */
                '../views/404.vue')
            }, {
                path: '/403',
                name: '403',
                meta: {
                    title: '没有权限'
                },
                component: () => import (/* webpackChunkName: "403" */
                '../views/403.vue')
            }, {
                path: '/operLogTable',
                name: 'operLogTable',
                meta: {
                    title: '操作日志'
                },
                component: () => import (/* webpackChunkName: "operLogTable" */
                    '../views/log/OperLog.vue')
            }
            , {
                path: '/exceptionLogTable',
                name: 'exceptionLogTable',
                meta: {
                    title: '异常日志'
                },
                component: () => import (/* webpackChunkName: "exceptionLogTable" */
                    '../views/log/ExceptionLog.vue')
            }
        ]
    }, {
        path: "/login",
        name: "Login",
        meta: {
            title: '登录'
        },
        component: () => import (
        /* webpackChunkName: "login" */
        "../views/Login.vue")
    }, {
        path: "/register",
        name: "Register",
        meta: {
            title: '注册'
        },
        component: () => import (
            /* webpackChunkName: "register" */
            "../views/Register.vue")
        }
];

const router = createRouter({
    history: createWebHistory(process.env.BASE_URL),
    routes
});

// router.beforeEach((to, from, next) => {
//     document.title = `${to.meta.title} | vue-template`;
//     const role = localStorage.getItem('ms_username');
//     if (!role && to.path !== '/login') {
//         next('/login');
//     } else if (to.meta.permission) {
//         // 如果是管理员权限则可进入，这里只是简单的模拟管理员权限而已
//         role === 'admin'
//             ? next()
//             : next('/403');
//     } else {
//         next();
//     }
// });

export default router;
